<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" @keyup.enter="search" v-model="query">
        <img :src="musicImg" style="width:100px;height:100px;">
        <audio ref="audio" :src="musicUrl" controls autoplay loop></audio>
        <ul>
            <li v-for="(item,index) in list"><button @click="play(item.id)">播放</button>{{item.name}}</li>
        </ul>
    </div>
    <script>
        var app = new Vue({
            el:"#app",
            data:{
                query:"",
                list:[],
                musicUrl:"",
                musicImg:""
            },
            methods:{
                search:function(){
                    var thisA = this;
                    axios.get("https://autumnfish.cn/search?keywords="+this.query)
                    .then(function(response){
                        console.log(response);
                        thisA.list = response.data.result.songs;
                    },function(err){
                        console.log(err);
                    })
                },
                play:function(id){
                    var thisA = this;
                     axios.get("https://autumnfish.cn/song/url?id="+id)
                     .then(function(response){
                         console.log(response);
                         thisA.musicUrl = response.data.data[0].url;
                     },function(err){
                         console.log(err);
                     })

                     axios.get("https://autumnfish.cn/song/detail?ids="+id)
                    .then(function(response){
                         console.log(response);
                         thisA.musicImg = response.data.songs[0].al.picUrl;
                     },function(err){
                         console.log(err);
                     })
                }
            }
        })
    </script>
</body>
</html>